﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using System.Configuration;
using BlogHunter.Util;
using BlogHunter.Manager;

namespace BlogHunter
{
    public class WinServiceApp
    {
        public void RunApp()
        {
            //Blog Array
            List<Blog> blogArray = new List<Blog>();

            //Get Blog from Subscribe List and add to Blog Array
            String[] subscribeList = ConfigurationSettings.AppSettings["SubscribeList"].Split('|');
            for (int i = 0; i < subscribeList.Length; i++)
            {
                String[] blogNameUriPair = subscribeList[i].Split(',');
                if (!String.IsNullOrEmpty(blogNameUriPair[0].Trim()) && !String.IsNullOrEmpty(blogNameUriPair[1].Trim()))
                {
                    Blog blog = BlogFactory.GetBlog(blogNameUriPair[0].Trim(), new Uri(blogNameUriPair[1].Trim()));
                    blogArray.Add(blog);
                }
            }

            //Loop each subscribe and ExecuteTasks. 
            foreach (Blog blog in blogArray)
            {
                blog.ExecuteTask();
            }
        }
    }
}
